import time

import openpyxl,xlrd
import threading,os
basefileNames=[]
def xx():
    fileName=r'C:\Users\谢谢\Desktop\123.xlsx'



    # 打开文件

    workbook=openpyxl.load_workbook(fileName)

    sheetNeed=workbook['Sheet1']
    for i in range(2, sheetNeed.max_row + 1):
        生产日期=str(sheetNeed.cell(i,12).value)
        print(生产日期,sheetNeed.cell(i,3).value,sheetNeed.cell(i,4).value)
        sheetNeed.cell(i, 12).value=f"{生产日期[:4]}-{生产日期[4:6]}-{生产日期[6:]}"
        if not sheetNeed.cell(i, 2).value:
            sheetNeed.cell(i, 2).value = f"{生产日期[:4]}-{生产日期[4:6]}-{生产日期[6:]}"
        else:
            生产日期=str(sheetNeed.cell(i,2).value)
            sheetNeed.cell(i, 2).value = f"{生产日期[:4]}-{生产日期[4:6]}-{生产日期[6:]}"
        if sheetNeed.cell(i, 9).value:
            规格=str(sheetNeed.cell(i, 9).value)
            a=规格.split('/')
            if len(a)==1:
                sheetNeed.cell(i,10).value=sheetNeed.cell(i,9).value
            else:
                sheetNeed.cell(i, 10).value = '/'.join(a[1:])
                sheetNeed.cell(i, 9).value = a[0]

    workbook.save(fileName)

def ceshi():
    fileName = r'C:\Users\谢谢\Desktop\产品信息 - 测试.xlsx'

    getDataId, getData = [], []
    # 打开文件
    # workbook = xlrd.open_workbook(fileName)
    workbook = openpyxl.load_workbook(fileName)
    getData = []
    for sheet in workbook:
        if sheet.title == 'Sheet2':
            pass
        for i in range(1, sheet.max_row + 1):
            item = []
            for j in range(1, sheet.max_column + 1):
                item.append(sheet.cell(i, j).value)
            getData.append(item)

        print(sheet.title)
    print(getData)
    sheetNeed = workbook.get_sheet_by_name('Sheet2')
    for index, item in enumerate(getData):
        print('1')
        for j in range(len(item)):
            sheetNeed.cell(index + 2, j + 1).value = item[j]

    workbook.save(fileName)

def chongfu():
    fileName = r'C:\Users\谢谢\Desktop\123.xlsx'

    # 打开文件

    workbook = openpyxl.load_workbook(fileName)

    sheetNeed = workbook['Sheet1']
    for i in range(2, sheetNeed.max_row + 1):
        品名=str(sheetNeed.cell(i-1,3).value)
        批号=str(sheetNeed.cell(i-1,4).value)
        if str(sheetNeed.cell(i,3).value)==品名 and str(sheetNeed.cell(i,4).value)==批号:
            print(品名,批号)
            sheetNeed.cell(i - 1, 3).value=""
    workbook.save(fileName)
def bianliwenj(files):
    for root,dirs,files in os.walk(files):
        for file in files:
            basefileNames.append([file,os.path.join(root,file)])
def ccccc():
    app_dist={}

    app_dist['ZJReportPath']=r"E:\公司资料"
    for file in os.listdir(app_dist['ZJReportPath']):
        if os.path.isfile(os.path.join(app_dist['ZJReportPath'], file)):  # 如果是文件，则导入
            basefileNames.append([file, os.path.join(app_dist['ZJReportPath'], file)])
        else:

            for fil in os.listdir(os.path.join(app_dist['ZJReportPath'], file)):
                if os.path.isfile(os.path.join(app_dist['ZJReportPath'], file, fil)):  # 如果是文件，则导入
                    basefileNames.append([fil, os.path.join(app_dist['ZJReportPath'], file, fil)])
                else:
                    for fi in os.listdir(os.path.join(app_dist['ZJReportPath'], file,fil)):
                        if os.path.isfile(os.path.join(app_dist['ZJReportPath'], file, fil,fi)):  # 如果是文件，则导入
                            basefileNames.append([fi, os.path.join(app_dist['ZJReportPath'], file, fil,fi)])
                        else:
                            thread1 = threading.Thread(
                                target=lambda: bianliwenj(os.path.join(app_dist['ZJReportPath'], file, fil,fi)))
                            thread1.start()


    print(len(basefileNames))
    time.sleep(0.3)
    print(len(basefileNames))
ccccc()

